import request from '../../request';
import { AxiosResponse } from 'axios';
import { ResponseData } from '@/types/api/public';
import { TableList,EditData,FormInput } from '@/types/api/form/form';

type ConfigType<T=ResponseData> = Promise<AxiosResponse<T>>

/**
 * 获取数据
 * @param params 参数
 * @returns 分页数据
 */
export const getData =(params:any):ConfigType<TableList> =>{
    params.PageIndex=params.current;
    params.PageSize=params.pageSize;
   
    return request({
       url:'/api/v1/Form/GetFormPageList',
       method:'get',
       params,   
       headers: {
        'Content-Type': 'application/json'
      } 
    })
}



/**
 * 删除表单
 * @param params 参数
 * @returns 操作结果
 */
export const delForm =(params:any):ConfigType =>{
  return request({
     url:'/api/v1/Form/DelFormById',
     method:'get',
     params,
      headers: {
          'Content-Type': 'application/json-patch+json'
        }
  })
}

/**
 * 新增表单记录
 * @param data 表单数据
 * @returns 新增结果
 */
export const addForm =(data:FormInput):ConfigType =>{
  return request({
     url:'/api/v1/Form/AddForm',
     method:'post',
     data,
      headers: {
          'Content-Type': 'application/json-patch+json'
        }
  })
}

/**
 * 更新表单
 * @param data 表单记录
 * @returns 返回表单更新结果
 */
export const updateForm =(data:FormInput):ConfigType =>{
  return request({
     url:'/api/v1/Form/UpdateForm',
     method:'post',
     data,
      headers: {
          'Content-Type': 'application/json-patch+json'
        }
  })
}

export const getlDataSourceTables =():ConfigType<TableList> =>{
  return request({
     url:'/api/v1/DataSource/GetAllDataSourceTables',
     method:'get',
     headers: {
      'Content-Type': 'application/json'
    } 
  })
}

export const getlDataSourceColumns =(params:any):ConfigType<TableList> =>{
  return request({
     url:'/api/v1/DataSource/GetDataSourceColumnsByTableId',
     method:'get',
     params,
     headers: {
      'Content-Type': 'application/json'
    } 
  })
}

export const saveOrUpdateFormDataSourceRef =(data:any):ConfigType =>{
  return request({
     url:'/api/v1/FormDataSource/SaveOrUpdateFormDataSourceRef',
     method:'post',
     data,
      headers: {
          'Content-Type': 'application/json-patch+json'
        }
  })
}

export const getFormColumnRefDataSourceList =(params:any):ConfigType<TableList> =>{
  return request({
     url:'/api/v1/FormDataSource/GetFormColumnRefDataSourceList',
     method:'get',
     params,
     headers: {
      'Content-Type': 'application/json'
    } 
  })
}